*Set directories below and output appendix tables and figures


global dataoutput		= "${path}data/"
global results		= "${path}figures/"


/*******************************************************************************************/
/* Table A.1: DMs' Willingness-to-Pay for Additional Meetings and Self-reported Management */
/*******************************************************************************************/

	use "${dataoutput}DMs_experiment.dta", clear
	
	foreach var in wtp__b wtp__a  wtp__b_comp{
	eststo OLSITT`var': qui reg `var'0 Treated  i.strata modeEND noEND  missingspeak* missingR0,  cluster(Team)
}
	rename Treated instrument
	rename Takeup Treated
 
	foreach var in wtp__b wtp__a wtp__b_tran wtp__b_comp{
	eststo OLSTOT`var': qui ivreg2 `var'0 (Treated=instrument) i.strata modeEND noEND  missingspeak* missingR0, cluster(Team)
	}
 	
	use "${dataoutput}DMs_experiment.dta", clear

	*drop outcomes if no endline response
	replace people0=. if noEND==1
	replace target0=. if noEND==1

	foreach var in people target mngt_score {
	eststo OLSITT`var': qui areg `var'0 Treated `var'1 modeEND noEND , a(strata)  vce (cluster Team)
	}
	rename Treated instrument
	rename Takeup Treated

	foreach var in people target  mngt_score {
	eststo OLSTOT`var': qui ivreg2 `var'0 (Treated=instrument) `var'1 modeEND noEND  i.strata , cluster(Team ) 
	}
	
	*Table
	*Panel A
	esttab OLSITTwtp__b OLSTOTwtp__b  OLSITTwtp__b_comp OLSTOTwtp__b_comp OLSITTwtp__a OLSTOTwtp__a, ///
	keep(Treated) 	
	
	*Panel B
	esttab OLSITTmngt_score OLSTOTmngt_score OLSITTpeople OLSTOTpeople ///
	OLSITTtarget OLSTOTtarget, keep(Treated)


/*******************************************************************************************/
/******************** Figure C.1: English Proficiency of DMs and FMs  **********************/
/*******************************************************************************************/
	
	use "${dataoutput}DMs_experiment.dta", clear
	
	encode bucket1, gen(bucket)
	encode bucket2, gen(bucket_act)
	
	gen placement_score_p=(placement_score/40)*100
	gen placement_score_p2=(placement_score2/40)*100	
	
	*Panel A	
	set scheme plotplainblind
	twoway (hist placement_score_p, width(15) discrete yaxis(1)) ///
	(kdensity placement_score_p, lcolor(gs10) lstyle(bold) lwidth(thick) range(0 100) yaxis(2) ytitle("Density")), ///
	legend(off) ///
	ylabel(0 "0".01 "15" .02 "30" .03 "45" .04 "60", axis(1)) ///
	ytitle("Fraction of DMs (%)", axis(1)) ytitle("Density", axis(2)) xtitle("Language Provider's Test Scores, Before Course (%)") ///
	text(0.0408 5 "CEFR", place(r) size(small)) ///
	text(0.0392 5 "scale:", place(r) size(small)) ///	
	text(0.04 24.5 "<A1", place(c) size(small)) ///
	xline(32.5, lcolor(black)) ///
	text(0.04 40 "A1", place(c) size(small)) ///
	xline(47.5, lcolor(black)) ///
	text(0.04 55 "A2", place(c) size(small)) ///
	xline(62.5, lcolor(black)) ///
	text(0.04 70 "B1", place(c) size(small)) ///
	xline(77.5, lcolor(black)) ///
	text(0.04 85 "B2", place(c) size(small)) ///
	xline(92.5, lcolor(black)) ///
	text(0.04 96 "C1", place(c) size(small)) ///
	xline(99, lcolor(black)) ///
	text(0.04 101 "C2", place(c) size(small)) 
	graph export "${results}FigC1_A.pdf", as(pdf) replace
	
 	use "${dataoutput}FM_DM_matched.dta", clear

	bysort fm_id: gen num_fm=_n
	bysort id: gen num_dm=_n

	*Panel B
	set scheme plotplainblind	
	twoway (kdensity DMtot if num_dm==1) (kdensity FMtot if FMtot!=.&num_fm==1) , ///
	legend(label(1 "DM Score") label (2 "FM Score") pos(1) ring(0)) ytitle("Density") xtitle("English Test Scores at Baseline (%)") 
	graph export "${results}FigC1_B.pdf", as(pdf) replace


/*******************************************************************************************/
/******************** Table C.1: Baseline Balance for Language Experiment ******************/
/*******************************************************************************************/

	use "${dataoutput}DMs_experiment.dta", clear
	egen z_big5=std(big5)
	
	label var Male " \text{Male (\%)}"
	label var education " \text{Education (yrs)}"
	label var age " \text{Age (yrs)}"
	label var tenure " \text{Tenure (yrs)}"
	label var z_big5 " \text{Big 5 (z score)}"
	label var salary_USD1 " \text{Monthly salary (USD)}"
	label var eng_score_tot1 " \text{English score (\%)}"
	label var invt_score1 " \text{Involvement score (1-4)}"
	label var mngt_score1 " \text{Management score (/15)}"
	label var conv60b1 " \text{Time lost with FM (\%)}"
	label var talk_freq_b1 " \text{Talk Freq. FM (1-4)}"
	label var noEND " \text{Endline attrition (\%)}"

	global DESCVARS Male education age tenure z_big5 salary_USD1 eng_score_tot1 invt_score1 mngt_score1 conv60b1 talk_freq_b1 noEND
	mata: mata clear

foreach var in Male education {
    qui reg `var' Treated i.strata, vce(cluster Team)
    outreg, keep(Treated )  rtitle("`: var label `var''") stats(b se ) bdec(2) ///
        noautosumm store(row`i') starlevel(10 5 1)
    outreg, replay(diff) append(row`i') ctitles("",Difference ) ///
        store(diff) note("") starlevel(10 5 1)
}

foreach var in age{
    qui reg `var' Treated i.strata, vce(cluster Team)
    outreg, keep(Treated )  rtitle("`: var label `var''") stats(b se ) bdec(1) ///
        noautosumm store(row`i') starlevel(10 5 1)
    outreg, replay(diff) append(row`i') ctitles("",Difference ) ///
        store(diff) note("") starlevel(10 5 1)
}
 
 foreach var in  tenure z_big5 {
    qui reg `var' Treated i.strata, vce(cluster Team)
    outreg, keep(Treated )  rtitle("`: var label `var''") stats(b se ) bdec(2) ///
        noautosumm store(row`i') starlevel(10 5 1)
    outreg, replay(diff) append(row`i') ctitles("",Difference ) ///
        store(diff) note("") starlevel(10 5 1)
}
 
 foreach var in salary_USD1 {
    qui reg `var' Treated i.strata, vce(cluster Team)
    outreg, keep(Treated )  rtitle("`: var label `var''") stats(b se ) bdec(0) ///
        noautosumm store(row`i') starlevel(10 5 1)
    outreg, replay(diff) append(row`i') ctitles("",Difference ) ///
        store(diff) note("")
}
 
 foreach var in eng_score_tot1 {
 	qui reg `var' Treated i.strata, vce(cluster Team)
    outreg, keep(Treated )  rtitle("`: var label `var''") stats(b se ) bdec(1) ///
        noautosumm store(row`i') starlevel(10 5 1)
    outreg, replay(diff) append(row`i') ctitles("",Difference ) ///
        store(diff) note("") starlevel(10 5 1)

 }
 
  foreach var in invt_score1 mngt_score1 conv60b1 talk_freq_b1 noEND {
 	qui reg `var' Treated i.strata, vce(cluster Team)
    outreg, keep(Treated )  rtitle("`: var label `var''") stats(b se ) bdec(2) ///
        noautosumm store(row`i') starlevel(10 5 1)
    outreg, replay(diff) append(row`i') ctitles("",Difference ) ///
        store(diff) note("") starlevel(10 5 1)

 }
 
outreg, replay(diff)

foreach var in Male education {
    qui reg `var' Treated, vce(cluster Team)
    outreg, keep(_cons)  rtitle("`: var label `var''") stats(b se ) bdec(2) ///
        noautosumm store(row`i') nostar
    outreg, replay(cons) append(row`i') ctitles("",Difference ) ///
        store(cons) note("")
}
 
foreach var in age {
    qui reg `var' Treated, vce(cluster Team)
    outreg, keep(_cons)  rtitle("`: var label `var''") stats(b se ) bdec(1) ///
        noautosumm store(row`i') nostar
    outreg, replay(cons) append(row`i') ctitles("",Difference ) ///
        store(cons) note("")
}

foreach var in  tenure z_big5  {
    qui reg `var' Treated, vce(cluster Team)
    outreg, keep(_cons)  rtitle("`: var label `var''") stats(b se ) bdec(2) ///
        noautosumm store(row`i') nostar
    outreg, replay(cons) append(row`i') ctitles("",Difference ) ///
        store(cons) note("")
}

foreach var in salary_USD1 {
    qui reg `var' Treated, vce(cluster Team)
    outreg, keep(_cons)  rtitle("`: var label `var''") stats(b se ) bdec(0) ///
        noautosumm store(row`i') nostar
    outreg, replay(cons) append(row`i') ctitles("",Difference ) ///
        store(cons) note("")
}

foreach var in eng_score_tot1  {
    qui reg `var' Treated, vce(cluster Team)
    outreg, keep(_cons)  rtitle("`: var label `var''") stats(b se ) bdec(1) ///
        noautosumm store(row`i') nostar
    outreg, replay(cons) append(row`i') ctitles("",Difference ) ///
        store(cons) note("")
}
foreach var in invt_score1 mngt_score1 conv60b1 talk_freq_b1 noEND {
    qui reg `var' Treated, vce(cluster Team)
    outreg, keep(_cons)  rtitle("`: var label `var''") stats(b se ) bdec(2) ///
        noautosumm store(row`i') nostar
    outreg, replay(cons) append(row`i') ctitles("",Difference ) ///
        store(cons) note("")
}
outreg, replay(cons) merge(diff) store(md)

local count: word count $DESCVARS
mat sumstat = J(2*`count',1,.)

local i = 1
foreach var in $DESCVARS {
    quietly: summarize `var'
    mat sumstat[`i',1] = r(N)
	local i = `i' + 2
}
frmttable, statmat(sumstat) store(sumstat) sfmt(g)

	*Table
	outreg, ///
		replay(md) merge(sumstat) tex nocenter fragment plain replace ///
		ctitles("", "Control", "Treatment diff", "N") nostar
	

/*******************************************************************************************/
/*************************** Table C.3: English Usage Outside of MNC ***********************/
/*******************************************************************************************/

	use "${dataoutput}DMs_experiment.dta", clear

	*drop outcomes if no endline response
	replace people0=. if noEND==1
	replace target0=. if noEND==1

	foreach var in uses_english_0 uses_english_a uses_english_2 uses_english_3 uses_english_4 uses_english_5 uses_english_6 uses_english_7 uses_english_8 uses_english_9 uses_english_10  {
	qui eststo OLSITT`var': areg `var'0 Treated `var'1 modeEND noEND , a(strata)  vce (cluster Team)
	}
	
	rename Treated instrument
	rename Takeup Treated

	foreach var in uses_english_0 uses_english_a uses_english_2 uses_english_3 uses_english_4 uses_english_5 uses_english_6 uses_english_7 uses_english_8 uses_english_9 uses_english_10  {
	qui eststo OLSTOT`var': ivreg2 `var'0 (Treated=instrument) `var'1 modeEND noEND  i.strata , cluster(Team ) 
	}
	
	*Table
	*Panel A
	esttab OLSITTuses_english_0 OLSTOTuses_english_0 OLSITTuses_english_a OLSTOTuses_english_a  OLSITTuses_english_2 OLSTOTuses_english_2 OLSITTuses_english_3 OLSTOTuses_english_3 OLSITTuses_english_4 OLSTOTuses_english_4, keep(Treated) compress
	
	*Panel B
	esttab OLSITTuses_english_5 OLSTOTuses_english_5 OLSITTuses_english_6 OLSTOTuses_english_6 OLSITTuses_english_7  OLSTOTuses_english_7 OLSITTuses_english_8  OLSTOTuses_english_8, keep(Treated)	compress


/*******************************************************************************************/
/**************************** Table C.4: Spillovers to Control DMs *************************/
/*******************************************************************************************/

	use "${dataoutput}DMs_experiment.dta", clear
	
	replace share_Team=share_Team*100

	foreach var in z_eng z_speak z_tot talk_freq_b talkfreqFMB conv60b  mngt_score people target mngt_score talk_freq_a {		
	qui eststo sOLSITT`var': qui areg `var'0 Treated `var'1  share_Team modeEND if Treated==0, a(strata)  vce (cluster Team)
	}
	
	foreach var in mtg_foreign_first mtg_DM_first wtp__b wtp__b_comp wtp__a time_b {
	qui eststo sOLSITT`var': qui areg `var'0 Treated  share_Team modeEND if Treated==0, a(strata)  vce (cluster Team)
	}
	
	merge 1:m id using "${dataoutput}DMs_mngt_sim.dta", keepusing(task_version time_fm time_worker time_total mistake question) keep(3) nogen
	reshape wide time_fm time_worker time_total mistake question, i(id) j(task_version)
	*1 simple burmese 2 complex burmese 3 complex english.

	foreach var in time_fm time_worker time_total{
	forval i=1(1)3{
	replace `var'`i'=`var'`i'/60
	}
	}

	foreach var in time_worker mistake  time_fm question {		
	qui eststo sOLSITT`var'3: areg `var'3 Treated share_Team if Treated==0, a(strata)  cluster(Team)
	qui eststo sOLSITT`var'2: areg `var'2 Treated share_Team if Treated==0, a(strata)  cluster(Team)
}

	*Table
	*Panel A
	esttab sOLSITTz_tot sOLSITTtalk_freq_b sOLSITTtime_b sOLSITTconv60b sOLSITTpeople, ///
	keep(share_Team)
	
	*Panel B
	esttab sOLSITTtime_worker3 sOLSITTmistake3 sOLSITTtime_fm3 sOLSITTquestion3 sOLSITTtime_worker2 sOLSITTmistake2 sOLSITTtime_fm2 sOLSITTquestion2, keep(share_Team) 
	
	
/*******************************************************************************************/
/***************** Table C.5: Summary Statistics of Human Resource Managers ****************/
/*******************************************************************************************/

	use "${dataoutput}Resume_data.dta", clear

	drop if o_pilot==1
	duplicates drop phone, force
	keep if company_origin==1
	
	replace birthyear=. if birthyear<0
	gen age_rater=2020-birthyear

	gen years_education=11 if education==5
	replace years_education=13 if education==6
	replace years_education=16 if education==7
	replace years_education=18 if education==8	
	gen male=gender=="Male"
	gen fdi=(company_origin!=1)	
	
	*Table
	estpost sum age_rater years_education work_exp company_exp_fdi resumes_6m recruit_6m recruitfdi_6m
	esttab .,  cell((mean(fmt(a0)) sd(fmt(a0)) count(fmt(a0))))
	

/*******************************************************************************************/
/************************* Figure C.2: Firms by Origin and Sector **************************/
/*******************************************************************************************/

	use "${dataoutput}Firms_salary_sheets.dta", clear
	drop if _m==2
	merge m:1 companyid using "${dataoutput}Firms.dta", keep(3) nogen
	collapse (first) sector industry origin_country, by(companyid)
	
	gen IND=industry
	replace IND="Other" if industry=="HR Support" | industry=="Real Estate" | industry=="Waste Management"  
	tab IND, sort gen(IND_)
	gen IND_12=IND_2
	drop IND_2
	
	gen country=origin_country
	replace country="China/HK" if regexm(country, "China") | regexm(country, "Hong")
	replace country="Myanmar/Japan JV" if regexm(country, "Myanmar")
	replace country="EU/USA" if regexm(country, "EU") | regexm(country, "USA") | regexm(country, "Virgin")

	gen COUNTRY=1 if country=="Japan"
	replace COUNTRY=2 if country=="Singapore"
	replace COUNTRY=3 if country=="Thailand"
	replace COUNTRY=4 if country=="China/HK"
	replace COUNTRY=5 if country=="EU/USA"
	replace COUNTRY=6 if country=="Korea"
	replace COUNTRY=7 if country=="Taiwan"
	replace COUNTRY=8 if country=="Myanmar/Japan JV"
		
	label define countrylabels 1 "Japan" 2 "Singapore" 3 "Thailand" 4 "China/HK" 5 "EU/USA" 6 "Korea" 7 "Taiwan" 8 "Myanmar/Japan JV" 
	label values COUNTRY countrylabels
	
	*Figure
	set scheme plotplainblind
	graph bar (sum) IND_*, over(COUNTRY, label(labsize(vsmall))) stack 	///
	ytitle("Number of firms") ytick(1(1)30) ylabel(0(5)30) ///
	legend(label(1 "Logistics") label(2 "Distribution") label(3 "Garment") label(4  "Chemicals") ///
	label(5 "Metal") label(6 "Packaging") label(7 "Construction") label(8 "Electronics") label(9 "Food and Beverage") label(10 "Machinery") label(11 "Other") pos(12) ring(0) row(2)) 
	
	graph export "${results}FigC2.pdf", as(pdf) replace


/*******************************************************************************************/
/*************** Figure C.3: Employees' Reasons for Working in the MNCs ********************/
/*******************************************************************************************/

	use "${dataoutput}Workers_aspirations.dta", clear
	
	gen manager=0 if  position_categ_large_self==2&position_categ_large==2
	replace manager=1 if position_categ_large_self==1&position_categ_large==1
	
	keep if !missing(manager)

	preserve	

	keep benefit* manager	
	
	forval num=1/7{
	gen benefit_dum_`num'=.
	foreach var of varlist benefit*{
	replace benefit_dum_`num'=1 if `var'==`num'
	}
	}
	replace benefit_dum_3=1 if benefit_dum_4==1
	drop benefit_dum_4
			
	collapse (sum) benefit_dum*, by(manager)
	egen total=rowtotal(benefit_dum*)
	
	forval i=1/3{
	replace benefit_dum_`i'=benefit_dum_`i'/total
	replace benefit_dum_`i'=benefit_dum_`i'*100
	format benefit_dum_`i' %9.2g
	}
	forval i=5/7{
	replace benefit_dum_`i'=benefit_dum_`i'/total
	replace benefit_dum_`i'=benefit_dum_`i'*100		
	format benefit_dum_`i' %9.2g
	}
	
	gen manager2="Managers"
	replace manager2="Production workers" if manager==0
	drop if manager==0

	*Panel A
	graph bar benefit_dum_1 benefit_dum_2 benefit_dum_3 benefit_dum_5 benefit_dum_6 benefit_dum_7, ///
	ytitle("% reported as main benefit") legend(pos(6) row(2) label(1 "Proximity")  label(2 "Good wage") label(3 "Good working condition") label(4 "New skills") label(5 "Other") label(6 "No benefit")) 
	graph export "${results}FigC3_A.pdf", as(pdf) replace 
	
	restore
	
	forval num=1/6{
	gen learned_skills_dum_`num'=.
		foreach var of varlist learned_skills*{
		replace learned_skills_dum_`num'=1 if `var'==`num'
		}
	}
	gen learned_skills_helper=learned_skills_dum_4
	replace learned_skills_dum_4=learned_skills_dum_3
	drop learned_skills_dum_3
	rename learned_skills_helper learned_skills_dum_3
		
	collapse (sum) learned_skills_dum*, by(manager)
	egen total=rowtotal(learned_skills_dum*)
	
	forval i=1/6{
	replace learned_skills_dum_`i'=learned_skills_dum_`i'/total
	replace learned_skills_dum_`i'=learned_skills_dum_`i'*100
	format learned_skills_dum_`i' %9.2g
	}	

	gen manager2="Managers"
	replace manager2="Production workers" if manager==0
	drop if manager==0
	
	*Panel B
	graph bar learned_skills_dum_1 learned_skills_dum_2 learned_skills_dum_3 learned_skills_dum_4 learned_skills_dum_5 learned_skills_dum_6, ///  
	ytitle("% reported as main skill") legend(pos(6) row(2) label(1 "Skills in production") label(2 "New machines") label(3 "Finance/accounting") label(4  "Management skills") label(5 "Other") label(6 "Nothing") size(vsmall))
	graph export "${results}FigC3_B.pdf", as(pdf) replace 
	
	
/*******************************************************************************************/
/****************** Figure C.4: Comparison with Language Provider's Test *******************/
/*******************************************************************************************/
	
	use "${dataoutput}DMs_experiment.dta", clear
	
	encode bucket1, gen(bucket)
	encode bucket2, gen(bucket_act)
	
	gen placement_score_p=(placement_score/40)*100
	gen placement_score_p2=(placement_score2/40)*100	
			
	reg engR0 placement_score_p
	local cons= string(_b[_cons],"%9.2f")
	local slope = string(_b[placement_score_p],"%9.2f")

	*Figure
	set scheme plotplainblind	
	twoway (scatter engR0 placement_score_p) (lfit engR0 placement_score_p, lstyle(dash)), ytitle("English Test Score at Baseline (%)") ///
	legend(off) xlabel(0(20)100) ///
	text(97 100 "y = `cons' + `slope'*X", place(l) size(small)) ///
	xtitle("Language Provider's Test Scores, Before Course (%)") 
	graph export "${results}FigC4.pdf", as(pdf) replace
	
/*******************************************************************************************/
/********* Figure C.5: Proficiency of DMs in Native Language of FMs and Vice Versa *********/
/*******************************************************************************************/

	use "${dataoutput}DMs.dta", clear	
	merge 1:m id using "${dataoutput}FM_DM_matched.dta"
	
	*Figure
	twoway (kdensity xxx_score_tot) (kdensity FMmya_score_tot), /// 
	legend(label(1 "DM score in FM's Native language") label (2 "FM score in Burmese") pos(1) ring(0) row(2)) ytitle("Density") xtitle("Other foreign language score in %")  
	graph export "${results}FigC5.pdf", as(pdf) replace

/*******************************************************************************************/
/************************* Figure C.6: Attendance by Treatment DMs *************************/
/*******************************************************************************************/

	use  "${dataoutput}DMs_experiment", clear

	keep if !missing(attend)
	collapse (count) Treated, by(attend)
	
	*manual adjustments
	set obs 25
	replace Treated=0 if missing(Treated)
	bysort Treated: replace attend=_n if missing(attend)
	replace attend=5 if attend==1&Treated==0
	replace attend=6 if attend==2&Treated==0
	replace attend=7 if attend==4&Treated==0
	sort attend
	
	gen cdf=Treated
	replace cdf=cdf+cdf[_n-1] if _n!=1
	g cdf2=154
	replace cdf2=cdf2-cdf[_n-1]
	replace cdf2=154 if missing(cdf2)
	replace cdf2=(cdf2/154)*100
	
	g attend2=(attend*100/24)
	drop if attend2==0
	
	*Figure
	set scheme plotplainblind
	twoway bar cdf2 attend2, ytitle("Share of Treatment (%)") xtitle("Share of training attended (%)") ///
	xlabel(0 "0" 20 "20" 40 "40" 60 "60" 80 "80" 100 "100") fintensity(0) yscale(r(0 100)) ///
	ylabel(0 "0" 20 "20" 40 "40" 60 "60" 80 "80" 100 "100")
	graph export "${results}FigC6.pdf", as(pdf) replace	
		
/*******************************************************************************************/
/********************* Figure C.7: Non-Contractibility of Communication ********************/
/*******************************************************************************************/

	*opportunity cost of FM by firm
	use "${dataoutput}Firms_salary_sheets.dta", clear
	keep if pos=="Expat" & lang_sample==1
	rename monthly_tot_USD fm_wages_firm
	keep companyid fm_wages_firm
	
	tempfile fm_wages_firm
	save `fm_wages_firm'
		
	*opportunity cost of FM by nationality and then linked to firm nationality
	use "${dataoutput}DMs_salary_sheets.dta", clear
	keep if pos=="Expat"
	replace nationality="korea" if missing(nationality)
	collapse (mean) monthly_tot_USD, by(nationality)
	
	tempfile fm_wages_nationality
	save `fm_wages_nationality'
	
	use "${dataoutput}Firms.dta", clear
	keep companyid origin_country
	
	merge 1:1 companyid using `fm_wages_firm', keep(3) nogen

	gen nationality=strlower(origin_country)
	replace nationality="china" if nationality=="hong kong"
	merge m:1 nationality using "${tmp}fm_wages_nationality.dta", keep(1 3)
	
	egen mean_wage=mean(monthly_tot_USD)
	replace monthly_tot_USD=mean_wage if missing(monthly_tot_USD)
	rename monthly_tot_USD fm_wages_origin
	keep companyid fm_wages*
	gen fm_oc=fm_wages_firm
	replace fm_oc=fm_wages_origin if missing(fm_oc)

	tempfile fm_wages_wtp
	save `fm_wages_wtp'

	*fm_oc is firm level replaced by origin when firm level is missing
	use "${dataoutput}DMs_experiment.dta", clear
	decode strata, gen(companyid)
	merge m:1 companyid using `fm_wages_wtp'
	
	*hourly
	foreach var in fm_oc fm_wages_origin {
	gen `var'_day=`var'/23
	gen `var'_hour=`var'_day/8
	gen wedge_`var'=wtp__b0-`var'_hour
	}
		
	egen max_fm_wage=max(fm_oc_hour)
	
	summ fm_oc_hour
	global mean_fm_wage=r(mean)
	
	summ max_fm_wage
	global max_fm_wage=r(mean)
		   
	gen wtp__b0_2=wtp__b0 if wtp__b0<=100
	cumul wtp__b0_2, gen(wtp__b0_cumul)
	
	*Panel A	
	set scheme plotplainblind
	twoway (lpoly wtp__b0_cumul wtp__b0, sort), xtitle("DM WTP (USD)") ///
	xlabel(0 "0" ${mean_fm_wage} "Mean FM wage" ${max_fm_wage} "Max FM wage" 50 "50" 100 "100") ///
	xline(${mean_fm_wage}, lpattern(solid)) xline(${max_fm_wage}, lpattern(solid)) ytitle("CDF")
 	graph export "${results}FigC7_A.pdf", as(pdf) replace
	
	use "${dataoutput}DMs_experiment.dta", clear
	
	rename meeting_length_first_a meeting_length_a 
	rename meeting_length_first_ideal_a meeting_ideal_a 
	rename meeting_length_first_b meeting_length_b
	rename meeting_length_first_ideal_b meeting_ideal_b
	
	foreach var in meeting_length_a meeting_length_b meeting_ideal_a meeting_ideal_b{
		cumul `var', gen(`var'_cumul)
		replace `var'=`var'/60
		winsor2 `var', trim cuts(5 95)
	}

	*Panel B	
	twoway (lpoly meeting_ideal_b_cumul meeting_ideal_b, sort) (lpoly meeting_length_b_cumul meeting_length_b, sort), xtitle("Hours spent talking with FM in past 7 days") ytitle("CDF") legend(label(1 "Ideal amount") label(2 "Actual amount") pos(1) ring(0)) yscale(range(.2(.2)1)) ylabel(.2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1")
	graph export "${results}FigC7_B.pdf", as(pdf) replace

	
/*******************************************************************************************/
/**************************** Figure C.8: Language Training NPVs ***************************/
/*******************************************************************************************/

	use "${dataoutput}DMs_experiment.dta", clear
	
	*storing locals
	gen placement_score_p=(placement_score/40)*100
	gen placement_score_p2=(placement_score2/40)*100	
	*elementary: 33-47, advanced: 90-97 (by plugging into reg engR0 placement_score_p)
	sum engR0 // mean is 45 within elementary
	g z_adv=string((97-r(mean))/r(sd), "%2.1fc")
	destring z_adv, replace
	sum z_adv
	global z_adv=r(mean)
	
	*Coefficents from lang prog and CV exp
	use "${dataoutput}DMs_experiment.dta", clear
	reghdfe z_tot0 Treated z_tot1 modeEND noEND  missingspeak* missingR0, a(strata) vce(cluster Team)
	g eng_ITT=_b[Treated]
	sum eng_ITT 
	global ITT =r(mean) // ITT
	
	rename Treated instrument
	rename Train75 Treated
	
	ivreg2 z_tot0 (Treated=instrument) z_tot1 i.strata modeEND noEND  missingspeak* missingR0, cluster(Team) 
	g eng_TOT=_b[Treated]
	sum eng_TOT
	global TOT=r(mean) // TOT
		
	use "${dataoutput}Resume_data.dta", replace //all pilot ratings and attached cvs
	drop if o_pilot==1
	keep if company_origin==1 // only local firms
	reghdfe wage_usd i.ENGLISH##i.FDI  i.GENDER i.AGE i.FIRM_SIZE i.WORK_EX if exp==1, a(RATER pairs) vce(cluster RATER)
	g cv_eng=_b[1.ENGLISH]
	sum cv_eng
	global CVwage=r(mean)
	g eng_return=${ITT}*${CVwage}/${z_adv}
	
	/* NPV of DMs */
	use "${dataoutput}DMs_experiment.dta", clear
	keep id

	*baseline R0
	merge 1:1 id using "${dataoutput}DMs.dta", keep(3) nogen
	
	global CVwage=51.27
	global r=0.012
	replace salary_USDR0 =. if salary_USDR0 >1000
	
	gen NPV_ITT=1/${r}*(${ITT}*${CVwage}/${z_adv})-48*salary_USDR0/(22*8)
	gen NPV_TOT=1/${r}*(${ITT}*${CVwage}/${z_adv})-48*salary_USDR0/(22*8)
	
	replace NPV_ITT=NPV_ITT-300
	
	summ NPV_ITT
	global meanNPVDM_ITT=r(mean)
	
	*Panel A	
	hist NPV_ITT, xtitle("NPV of english training for DM (USD)") xline(${meanNPVDM_ITT}, lpattern(solid)) fcolor(none) frac
	graph export "${results}FigC8_A.pdf", as(pdf) replace
		
	use "${dataoutput}Firms.dta", clear
	
	keep if !missing(NPV)
	
	global prodpw=0.15
	global prodfm=0.19
	
	summ NPV
	global meanNPV=r(mean)
	
	*Panel B	
	hist NPV, width(500) fcolor(none) start(-2000) frac xline(${meanNPV}, lpattern(solid)) xtitle("NPV of english training for firm (USD)") xlabel(-2000(500)5000)
	graph export "${results}FigC8_B.pdf", as(pdf) replace

	
/*******************************************************************************************/
/********************** Figure C.9: Language Prices Across Providers ***********************/
/*******************************************************************************************/

	use "${dataoutput}language_providers.dta", clear

	*residuals
	g lstudent = log(tot_student)
		replace lstudent = 0 if lstudent==.
	foreach j in lat long {
			sum gps_`j'
			replace gps_`j' = r(mean) if gps_`j'==.
		}

	foreach j in begin interm {
		reg per_hour_USD_`j' gps_lat gps_long i.iso_certificate i.teacher_source i.source lstudent
		predict per_hour_USD_`j'_res,r
	}
	
	*Figures
		twoway (scatter per_hour_USD_begin id, ms(o) mc(gs8)) ///
			(scatter per_hour_USD_interm id, ms(dh) mc(gs12)) ///
			(scatter per_hour_USD_begin id if teacher_source==1, ms(Oh) mc(gs1)) ///
			(scatter per_hour_USD_interm id if teacher_source==1, ms(Oh) mc(gs1)), ///
			legend(order(1 "Beginner English" 2 "Intermediate English") ring(0) position(11)) ///
			xtitle("Company ID")ytitle("Price ($ student/hr)") ///
			xlabel(1 5(5)30 34) ylabel(0(1)8) nodraw name("a1",replace)

		twoway (scatter per_hour_USD_begin_res id, ms(o) mc(gs8)) /// 
			(scatter per_hour_USD_interm_res id, ms(dh) mc(gs)) ///
			(scatter per_hour_USD_begin_res id if teacher_source==1, ms(Oh) mc(gs1)) ///
			(scatter per_hour_USD_interm_res id if teacher_source==1, ms(Oh) mc(gs1)), ///
			legend(order(1 "Beginner English" 2 "Intermediate English") ring(0) position(11)) ///
			xtitle("Company ID") ytitle("Price ($ student/hr), Residual") ///
			xlabel(1 5(5)30 34) ylabel(-1(1)3) nodraw name("a1r",replace)
		
		graph combine a1 a1r
		graph export "${results}FigC9.pdf",as(pdf) replace



